home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cgraphix / kdrawtxt.c < prev    next >
Text File  |  1986-05-08  |  3KB  |  128 lines

  1. /* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
  2. #include    <stdio.h>
  3. #define    EXTERN    extern
  4. #include    <typedef.h>
  5.  
  6.  
  7. void DrawAscii(x, y, size, ch)
  8. int        *x, *y, size, ch;
  9. {
  10.     int        x1ref,x2ref,xpos,ypos,xstart,ystart,xend,yend,xx,yy;
  11.     unsigned char    CharByte;
  12.     unsigned         mask;
  13.  
  14.     x1ref = X1RefGlb * 8;
  15.     x2ref = (X2RefGlb * 8) + 7;
  16.     for (ypos = 0; ypos <= 5; ypos++) {
  17.         CharByte=(CharSet[3*(ch-32)+2-(int)(ypos/2)]>>((ypos%2)? 4:0))&0x0f;
  18.  
  19.         mask = 8;
  20.         for (xpos = 0; xpos <= 3; xpos++) {
  21.             if (CharByte & mask) {                /* is a pixel to plot        */
  22.                 xstart = (*x) + xpos * size;
  23.                 xend = xstart + size - 1;
  24.                 ystart = (*y) + 1 + (ypos - 2) * size;
  25.                 yend = ystart + size - 1;
  26.                 if (ClippingGlb) {
  27.                     if (xstart < x1ref)
  28.                         xstart = x1ref;
  29.                     if (xend > x2ref)
  30.                         xend = x2ref;
  31.                     if (ystart < Y1RefGlb)
  32.                         ystart = Y1RefGlb;
  33.                     if (yend>Y2RefGlb)
  34.                         yend = Y2RefGlb;
  35.                 }
  36.                 for (yy = ystart; yy <= yend; yy++)
  37.                     for (xx = xstart; xx <= xend; xx++)
  38.                         DP(xx,yy);
  39.             }
  40.             mask = mask >> 1;
  41.         }
  42.     }
  43.     *x = *x + 6 * size;
  44. }
  45.  
  46.  
  47. void DrawText(x, y, scale, txt)
  48. int        x, y, scale;
  49. char    *txt;
  50. {
  51.     int        LineStyleLoc, code, AsciiValue, StringLen, i;
  52.     int        SymbolScale, SymbolCode;
  53.     int        DirectModeLoc;
  54.  
  55.     DirectModeLoc = DirectModeGlb;
  56.     DirectModeGlb = TRUE;
  57.     LineStyleLoc = LineStyleGlb;
  58.     SetLineStyle(0);
  59.     StringLen = strlen(txt);
  60.     i = 0;
  61.     while (i < StringLen) {
  62.         AsciiValue = txt[i];
  63.         if (AsciiValue == 27) {
  64.             SymbolScale = scale;
  65.             i = i+1;
  66.             if (i <= StringLen) {
  67.                 SymbolCode = txt[i] - '0';
  68.                 if ((i+2 <= StringLen) && (txt[i+1] == 64)) {
  69.                     SymbolScale = txt[i+2] - '0';
  70.                     i = i + 2;
  71.                 }
  72.                 switch (SymbolCode) {
  73.                     case 1:
  74.                         DrawCross(x+SymbolScale,y+scale,SymbolScale);
  75.                         break;
  76.                     case 2:
  77.                         DrawCrossDiag(x+SymbolScale,y+scale,SymbolScale);
  78.                         break;
  79.                     case 3:
  80.                     case 4:
  81.                         DrawSquareC(x, y + (SymbolScale * 2) - 1,
  82.                             x + (SymbolScale * 2), y - 1, (SymbolCode == 4));
  83.                         break;
  84.                     case 5:
  85.                         DrawDiamond(x + (int)(1.5 * SymbolScale),
  86.                             y + SymbolScale - 1, SymbolScale + 1);
  87.                         x = x + SymbolScale;
  88.                         break;
  89.                     case 6:
  90.                         DrawWye(x + SymbolScale, y + SymbolScale - 1,
  91.                             SymbolScale);
  92.                         break;
  93.                     case 7:
  94.                         DrawStar(x+SymbolScale * 2, y + SymbolScale - 1,
  95.                             SymbolScale);
  96.                         x = x + SymbolScale * 2;
  97.                         break;
  98.                     case 8:
  99.                         DrawCircleDirect(x+SymbolScale,y+(SymbolScale >> 1),
  100.                             SymbolScale+1,FALSE);
  101.                         break;
  102.                 }
  103.                 x = x + 3 * SymbolScale;
  104.                 SymbolScale = scale;
  105.             }
  106.         }
  107.         else
  108.             DrawAscii(&x, &y, scale, AsciiValue);
  109.         i = i+1;
  110.     }
  111.     DirectModeGlb = DirectModeLoc;
  112.     SetLineStyle(LineStyleLoc);
  113. }
  114.  
  115.  
  116. void DrawTextW(x, y, scale, txt)
  117. double    x, y;
  118. int        scale;
  119. char    *txt;
  120. {
  121.     if (DirectModeGlb)
  122.         DrawText((int)x, (int)y, scale, txt);
  123.     else
  124.         DrawText(WindowX(x), WindowY(y), scale, txt);
  125. }
  126.  
  127.  
  128.